Skip to content

Conversation

@lonelyclick
Copy link
Contributor

Similar redux-logger, add custom console implemenet redux-logger#options

for example, I can use it like this:

-> logger.js

const doConsole = (level, ...args) => {
  if (typeof console === 'undefined') return;

  const fn = console[level]; // eslint-disable-line no-console
  const isDev = process.env.NODE_ENV !== 'production';
  const enableByLocalStorage = typeof localStorage !== 'undefined' && 
    localStorage.getItem('enable_production_log');

  if (fn && (isDev || enableByLocalStorage)) {
    fn.apply(console, args);
  }
};

export default [
  'debug',
  'error',
  'info',
  'log',
  'warn',
  'dir',
  'table',
  'trace',
  'group',
  'groupCollapsed',
  'groupEnd',
].reduce((result, current) => ({
  ...result,
  [current](...args) {
    return doConsole(current, ...args);
  },
}), {});

-> plugins.js

import logger from './logger'

createLogger({
  collapsed: false,
  logger,
});

Copy link
Member

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice 🙂

@ktsn ktsn added the proposal label May 14, 2017
@yyx990803 yyx990803 merged commit 804c3bb into vuejs:dev Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants